/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1651816292405_8830';

  // add your middleware config here
  config.middleware = ['errorHandler', 'auth'];

  config.auth = {
    // 不需要经过验证
    ignore:['/reg','/login','/ws']
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  // 配置跨域内容
  config.security = {
    // 关闭 csrf
    csrf: {
      enable: false,
    },
    // 跨域白名单
    // domainWhiteList: ['http://localhost:8080'],
    domainWhiteList: [],
  };
  // 允许跨域的方法
  config.cors = {
    origin: '*',
    allowMethods: 'GET, PUT, POST, DELETE, PATCH'
  };

  // 配置sequelize 数据库
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    username: 'root',
    password: '123456',
    port: 3306,
    // 数据库名称
    database: 'egg-wechat',
    // 中国时区
    timezone: '+08:00',
    define: {
      // 取消数据表明复数
      freezeTableName: true,
      // 自动写入时间戳 created_at updated_at
      timestaps: true,
      // 字段生成软删除时间戳 deleted_at
      //paranoid: true,
      createdAt: 'created_at',
      updatedAt: 'updated_at',
      //deletedAt: 'deleted_at',
      // 所有驼峰命名格式化
      underscored: true
    }
  };

  // 配置sequelize 数据库
  config.valparams = {
    locale: 'zh-cn',
    // 是否抛出异常
    throwError: true
  };

  // 配置 crypto 数据加密
  config.crypto = {
    // 密钥可以随便写(写了之后就不要改了)
    secret: 'qhDgW@45ncashdaksh2!#@3nxJDas*_672'
  };

  // jwt鉴权
  exports.jwt = {
    // 密钥
    secret: 'qhDgW@56ncashdaksh3!#@4nxJDas*_118'
  };

  // redis存储
  config.redis = {
    client: {
      port: 6379,         // Redis post
      host: '127.0.0.1',  // Redis host
      password: '123456',
      db: 0
    }
  };

  // oss对象存储
  config.oss = {
    client: {
      accessKeyId: 'LTAI5tDSZfKko527LTG4r3b5',
      accessKeySecret: 'yYgTmndsYgur2UUGEPeV5lal3zUy0i',
      bucket: 'egg-wechatupload',
      endpoint: 'oss-cn-guangzhou.aliyuncs.com',
      timeout: '60s'
    }
  };
  config.multipart= {
    mode: 'file',
    // 默认是2M的大小
    fileSize: 1048576000
  };

  return {
    ...config,
    ...userConfig,
  };
};
